//
//  STWindow.swift
//  onemeetingmac
//
//  Created by 张衡 on 2020/10/9.
//  Copyright © 2020 onemeeting. All rights reserved.
//

import Foundation

class STWindow: NSWindow {
    var identifier_ktitle = NSToolbarItem.Identifier.init("identifier_ktitle")
    
    lazy var ktitle: NSLabel = {
        let lab = NSLabel.label(title: "设置", textColor: color_gray(0), font: NSFont.systemFont(ofSize: 16))
        lab.alignment = .center
        lab.sizeToFit()
        return lab
    }()
    
    override init(contentRect: NSRect, styleMask style: NSWindow.StyleMask, backing backingStoreType: NSWindow.BackingStoreType, defer flag: Bool) {
        super.init(contentRect: contentRect, styleMask: style, backing: backingStoreType, defer: flag)
        self.toolbar = self.customToolbar
    }
    
    lazy var customToolbar: NSToolbar = {
        let tool = NSToolbar.init(identifier: "STWindow")
        tool.sizeMode = NSToolbar.SizeMode.regular
        tool.delegate = self
        return tool
    }()
    
    
}

extension STWindow:NSToolbarDelegate {
    
    func toolbarIdentifiers() -> [NSToolbarItem.Identifier] {
        return [
            NSToolbarItem.Identifier.flexibleSpace,
            identifier_ktitle,
            NSToolbarItem.Identifier.flexibleSpace,
        ]
    }
    func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
        return self.toolbarIdentifiers()
    }
    
    func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
        return self.toolbarIdentifiers()
    }
    
    func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? {
        let toolbarItem = NSToolbarItem.init(itemIdentifier: itemIdentifier)
        if itemIdentifier.rawValue.isSame(to: identifier_ktitle.rawValue) {
            toolbarItem.view = self.ktitle
            return toolbarItem
        }else {
            return nil
        }
        
    }
    
    
}
